package com.cyy.system.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.cyy.common.domain.Response;
import com.cyy.common.pojo.dto.MenuFormDto;
import com.cyy.common.pojo.dto.MenuOptionDto;
import com.cyy.common.pojo.dto.MenuTreeDto;
import com.cyy.common.pojo.query.system.SystemMenuQuery;
import com.cyy.common.service.MenuService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "菜单")
@RestController
@RequestMapping("/system/menus")
@RequiredArgsConstructor
@SaCheckLogin
public class MenuController {

    private final MenuService menuService;


    @GetMapping("/treeMenus")
    public Response treeMenus(SystemMenuQuery query) {
        List<MenuTreeDto> res = menuService.treeMenus(query);
        return Response.success().data(res);
    }

    @GetMapping("/getMenuOptions")
    public Response getMenuOptions() {
        List<MenuOptionDto> res = menuService.getMenuOptions();
        return Response.success().data(res);
    }


    @GetMapping("/{id}/form")
    public Response getById(@PathVariable(name = "id") Integer id) {
        MenuFormDto res = menuService.getFormItemById(id);
        return Response.success().data(res);
    }

    @PostMapping("/editMenu")
    public Response editMenu(@RequestBody MenuFormDto req) {
        menuService.editMenu(req);
        return Response.success();
    }

    @DeleteMapping("/deleteMenu/{id}")
    public Response deleteMenu(@PathVariable(name = "id") Integer id) {
        menuService.deleteMenu(id);
        return Response.success();
    }

    @PostMapping("/addMenu")
    public Response addMenu(@RequestBody MenuFormDto req) {
        menuService.addMenu(req);
        return Response.success();
    }
}
